<%@page import="com.sq.partner.manager.util.StrUtil"%>
<%@page import="java.sql.Struct"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>关联销售信息</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>

	<style>
	    .select_1{width:250px;}
		.clearfix:before,
		.clearfix:after {
		   content: ".";
		   display: block;
		   height: 0;
		   visibility: hidden;
		}
		.clearfix:after {clear: both;}
		.clearfix {zoom: 1;} /* IE < 8 */
	</style>
	
	<script type="text/javascript">
	var commRate;
	/*----------- 初始化 ------------------- */
	function init() {
		//加载出库卡单信息
		queryCarTemplate('1');
		//加载方案信息
		queryNlifePlan();
		//从销管处取得业务员-团队信息
		querySauserAndTeamInfo(); 
	}
	$(function(){
		init();
	});
	/*----------- 初始化 ------------------- */
	/* 查询卡出库记录*/
	function queryCarTemplate(displayPage){
		var cardDefineId = $("#cardDefineId").val();
		var name= $("#name").val();
		var cardNo= $("#cardNo").val();
		var count= $("#count").val();
		var deptNo = $("#deptNo").val();
		//console.log(name)
		loadQueryData({current:displayPage,size:10,name: name, cardNo: cardNo, count:count,deptNo:deptNo});
	}
	function loadQueryData(param){
		var jsonDate;
		if(null != param && null != param.current){
			jsonDate =param;	
		}else{
			jsonDate={current:1,size:10};
		}
		//console.log(param)
		$.openLoading_jhk();
		$.ajax({
			url : "outboundCard/outboundCardList",
			type : 'POST',
			async : true,
			dataType:'json',
			data:jsonDate,
			success : function(page) {
				$.closeLoading();
				if($.validate(page))return;
				$("#row_num").val(page.total);
				var fieldNames = "name,cardNo,totPremAmtStr,disableDateStr";
				var tableContent = creatTable4(fieldNames, page, null, null);
				var tableObj = $("#cardInfoTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				
				var strPage = creatChannelPage(page.current,6,page.maxPage,"72");
				var pageDIV = $("#txCardpageDIV");
				pageDIV[0].innerHTML="";
				pageDIV.append(strPage);
			}
		})
	}
	
	/* 查询关联方案信息*/
	function queryNlifePlan(){
		//var name= $("#name").val();
		var deptNo = $("#deptNo").val();
		var planNo = $("#planNo").val();
		//loadQueryCardPlan(name,deptNo);
		loadQueryCardPlan(planNo,deptNo);
	}
	//var plan_list;
	function loadQueryCardPlan(planNo,deptNo){
		$.openLoading_jhk();
		$.ajax({
			//url : "outboundCard/queryCardPlanList",
			url : "outboundCard/queryCardPlan",
			type : 'POST',
			async : true,
			dataType:'json',
			data:{planNo:planNo},
			success : function(result) {
				$.closeLoading();
                if($.validate(result))return;
				/* if("error"==result.result && ""!=result.message){
					$.message('error',result.message);
			    }
				if("fail"==result.result){
		    		$.message("error", "系统错误,请联系管理员");
		    	} */
                var planInfo = result.plan;
                var nlifeCoreProd = result.nlifeCoreProd;
				//if("success"==result.result&&""!=result.message){
					if(planInfo!=null){
						//$("#userSaleName").removeAttr("disabled").css("background-color","transparent");
						
						commRate=planInfo.commRate;
						//$("#agentRate").attr('placeholder','上限'+commRate);
						var singlePrem=$("#singlePrem").val();
						var totalPrem=$("#totalPrem").val();
						var singleAgentFee=(commRate*(Number(singlePrem))).toFixed(2);
						var totalAgentFee=(commRate*(Number(totalPrem))).toFixed(2);
						$("#singleAgentFee").val(singleAgentFee);
						$("#totalAgentFee").val(totalAgentFee);
						$("#agentRate").val(commRate.toFixed(2));
						$("#agentRate").attr('placeholder','上限'+commRate.toFixed(2));
						$("#agentRateHidden").html(commRate.toFixed(2));
						//$("#prodCode").val(planInfo.prodCode);
					}else{
						$.message('error','该激活卡还没有配置销售方案');
					}
					if(nlifeCoreProd!=null){
		                $('#prodSaleCode').val(nlifeCoreProd.prodSaleCode);
					}
				//}
			}
		})
	}
	var team_user_list;
	function querySauserAndTeamInfo(){
		var deptNo = $.trim($('#deptNo').val());
        $.openLoading_jhk();
        $.ajax({
            url : "<%=path%>/outboundCard/querySauserAndTeamInfo?"+new Date().getTime(),
            type : 'POST',
            async : true,
            data:{deptNo:deptNo},
            dataType:'json',
            success:function(result){
                $.closeLoading();
                if("error"==result.result && ""!=result.message){
                    $.message('error',result.message);
                }
                if("fail"==result.result){
                	$.message("error", "系统错误,请联系管理员");
                }
                if("success"==result.result){
	                var select = document.getElementById("empNo_select");
	                select.options.length = 0;
	                select.add(new Option("-----请选择-----",""));
	                team_user_list = result.data;
	                if(team_user_list != null){
	                    for (var i = 0; i < team_user_list.length; i++) {
	                        var option = new Option();
	                        option.text = team_user_list[i].USERCODE + "-" + team_user_list[i].USERNAME;
	                        option.title = team_user_list[i].USERCODE + "-" + team_user_list[i].USERNAME;
	                        option.value = team_user_list[i].USERCODE;
	                        select.add(option);
	                    }
	                }else{
	                	$.message("error", "此机构下没有业务员-团队信息！");
	                }
                }
            }
        });
	}
	//下拉框处理
    function loadSubCascadeList(codeType,parentCode,select_id){
        $.ajax({
            url : "<%=path%>/outboundCard/loadSubCascadeList?"+new Date().getTime(),
            type : 'POST',
            async : false,
            data:{codeType:codeType,parentCode:parentCode},
            dataType:'json',
            success:function(list){
                if($.validate(list))  return;
                var select = document.getElementById(select_id);
                select.options.length = 0;
                if (list != null) {
                    for (var i = 0; i < list.length; i++) {
                        var option = new Option();
                        option.text = list[i].codeName;
                        option.title = list[i].codeName;
                        option.value = list[i].code;
                        select.add(option);
                    }
                }
            }
        });
    }
    //归属渠道改变时
    function changeChannleCode_QD(){
        var channleCode_QD = $.trim($("#channleCode_QD").val());
        loadSubCascadeList("channel_type",channleCode_QD,"channleType");
        loadSubCascadeList("new_business_source","","newBsnsType");
        $("#bsnsType").val('');
        $("#bsnsType").attr("disabled",false);
        $("#bsnsType").css({"background-color": ""});
        agentInfoWrite();
        serviceInfoWrite();
    }
    //渠道类型改变时
    function changeChannleType(){
        var channleType = $.trim($("#channleType").val());
        loadSubCascadeList("new_business_source",channleType,"newBsnsType");
        $("#bsnsType").val('');
        $("#bsnsType").attr("disabled",false);
        $("#bsnsType").css({"background-color": ""});
        agentInfoWrite();
        serviceInfoWrite();
    }
    //新业务来源改变时
    function changeNewBsnsType(){
        var parentCode = $("#channleType").val();
        var newBsnsCode = $("#newBsnsType").val();
        agentInfoWrite();
        serviceInfoWrite(); 
        chooseBsnsType(parentCode,newBsnsCode);
        queryServiceNo()
    }
    //选择旧业务来源
    function chooseBsnsType(parentCode,newBsnsCode){
        $.ajax({
            url : "<%=path%>/outboundCard/chooseBsnsType",
            type : 'POST',
            async : false,
            data:{parentCode:parentCode,newBsnsCode:newBsnsCode},
            dataType:'json',
            success:function(data){
                    if($.validate(data))  return;
                    if (data != null) {
                        $("#bsnsType").val(data.otherCode);
                        if(data.otherCode.length!=0){
                            $("#bsnsType").css({"background-color": "#ccc"});
                            $("#bsnsType").attr("disabled",true);
                        }
                        bsnsTypeChange();
                    }
            }
        });
    }
    //旧业务来源
    function bsnsTypeChange(){
    	var newBsnsCode = $("#newBsnsType").val();
        var bsnsTypeCode = $("#bsnsType").val();
        //原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填，其他非必填
        if(bsnsTypeCode!="19002"&&bsnsTypeCode!="19003"){
            $("#agentNo").attr("disabled",true);
            $("#agentNo").css({"background-color": "#ccc"});
            $("#agentNo").val("");
            $("#protocolNo").val("");
            $("#protocolNo").css({"background-color": "#ccc"});
            $("#protocolNo").attr("disabled",true);
            $("#agentName").val("");
            $("#agentName").css({"background-color": "#ccc"});
            $("#agentName").attr("disabled",true);
            $("#agentNo ~ span").remove(".red");
            $("#protocolNo ~ span").remove(".red");
            $("#agentName ~ span").remove(".red");
            //非代理时手续费和手续费比例是0 bug修改 start
            $("#singleAgentFee").val('0.00');
            $("#totalAgentFee").val('0.00');
            $("#agentRate").val('0.00');
            //非代理时手续费和手续费比例是0 bug修改 end
            
        }else{
            $("#agentNo").attr("disabled",false);
            $("#agentNo").css({"background-color": ""});
            $("#protocolNo").attr("disabled",false);
            $("#protocolNo").css({"background-color": ""});
            $("#agentName").attr("disabled",false);
            $("#agentName").css({"background-color": ""});
            if($("#agentNo ~ span").length==0){
                $("#agentNo").parent().append("<span class='red' style='margin-left: -5px'>*</span>");
            }
            if($("#protocolNo ~ span").length==0){
                $("#protocolNo").parent().append("<span class='red' style='margin-left: -5px'>*</span>");
            }
            if($("#agentName ~ span").length==0){
                $("#agentName").parent().append("<span class='red' style='margin-left: -5px'>*</span>");
            }
            //非代理时手续费和手续费比例是0 bug修改 start
            var singlePrem=$("#singlePrem").val();
            var totalPrem=$("#totalPrem").val();
            var singleAgentFee=(commRate*(Number(singlePrem))).toFixed(2);
            var totalAgentFee=(commRate*(Number(totalPrem))).toFixed(2);
            $("#singleAgentFee").val(singleAgentFee);
            $("#totalAgentFee").val(totalAgentFee);
            $("#agentRate").val(commRate.toFixed(2));
            //非代理时手续费和手续费比例是0 bug修改 end
            //查询中介-协议信息
            queryAgentAndAgreeInfo();
        }
    }
    
    //代理人代码、代理协议号可输入状态
    function agentInfoWrite(){
        $('#agentNo_select_div').css('display','none').val("");
        $('#agentNo').show().attr("readonly",false).css('background-color','white').val('');
        $('#agentName').attr("readonly",false).css('background-color','white').val('');
        $('#protocolNo').attr("readonly",false).css('background-color','white').val('');
    }
    
    //服务代码、服务名称可输入状态
    function serviceInfoWrite(){
        $('#serviceCode_select_div').css('display','none').val("");
        $('#serviceCode').show().val('');
        
        $('#serviceName').attr("readonly",false).css('background-color','white').val('');
    }
    //业务员下拉框改变时，动态改变业务员名称和团队代码
    var TEAMList;//存放当前所选业务员对应的团队List，便于团队代码改变时，团队名称的同步改变
    function changeEmpNo(){
        var empNo_select = $.trim($("#empNo_select").val());
        if (empNo_select.length > 10) {
            $.message('error', "业务员代码长度不能超过10位！");
            return;
        }
        $("#empNo").val(empNo_select);
        channelInit(empNo_select);
        agentInfoWrite();
        serviceInfoWrite();
        
        if(empNo_select.length==0) {
            $("#empName").attr("readonly",false).css('background-color','transparent').val("");
            $("#teamCode_select").val("");
            $("#teamName").attr("readonly",false).css('background-color','transparent').val("");
            return;
        }
        var belongToChannelList=JSON.parse('${belongToChannelList}');
        if(null != team_user_list){
            for (var i = 0; i < team_user_list.length; i++) {
                var USERCODE = team_user_list[i].USERCODE;
                if(empNo_select == USERCODE){
                    $("#empName").attr("readonly",true).css('background-color','#ccc').val(team_user_list[i].USERNAME);
                    TEAMList = team_user_list[i].TEAMList;
                    var select = document.getElementById("teamCode_select");
                    select.options.length = 0;
                    select.add(new Option("-----请选择-----",""));
                    var select1 = document.getElementById("channleCode_QD");
                    select1.options.length = 0;
                    select1.add(new Option("-----请选择-----",""));
                    var option;
                    var option1;
                    if(null != TEAMList){
                        for (var j = 0; j < TEAMList.length; j++) {
                            option = new Option();
                            option.text = TEAMList[j].TEAMCODE + "-" + TEAMList[j].TEAMNAME;
                            option.title = TEAMList[j].TEAMCODE + "-" + TEAMList[j].TEAMNAME;
                            option.value = TEAMList[j].TEAMCODE;
                            select.add(option);
                            option1 = new Option();
                            for (var k = 0; k < belongToChannelList.length; k++) {
                                if (TEAMList[j].CHANNELNAME==belongToChannelList[k].code) {
                                    option1.text = belongToChannelList[k].codeName;
                                    option1.title = belongToChannelList[k].codeName;
                                    option1.value = belongToChannelList[k].code;
                                    select1.add(option1);
                            	}
                            }
                        }
                        return;
                    }else{
                        $.message('error',"此机构下没有团队信息！");
                        return;
                    }
                }
            }
        }else{
            $.message('error',"此机构下没有业务员信息！");
            return;
        }
    }
    //业务员代码变化时，渠道选项初期化
    function channelInit(empNo_select){
    	var select1 = document.getElementById("channleCode_QD");
        if(empNo_select.length==0){
            select1.options.length = 0;
            select1.add(new Option("-----请选择业务员代码-----",""));
        }

        var select2 = document.getElementById("channleType");
        select2.options.length = 0;
        select2.add(new Option("-----请选择归属渠道-----",""));

        var select3 = document.getElementById("newBsnsType");
        select3.options.length = 0;
        select3.add(new Option("-----请选择渠道类型-----",""));
        
        $("#bsnsType").val('');
        $("#bsnsType").attr("disabled",false);
        $("#bsnsType").css({"background-color": ""});
    }
    //团队代码改变时，动态改变团队名称
    function changeTeamCode(){
        var teamCode_select = $.trim($("#teamCode_select").val());
        var teamCode = $.trim($("#teamCode").val());
        if (teamCode_select.length > 11) {
            $.message('error', "团队代码长度不能超过11位！");
            return;
        }
        $("#teamCode").val(teamCode_select);
        if(teamCode_select.length==0) {
            $("#teamName").attr("readonly",false).css('background-color','transparent').val("");
            return;
        }
        if(null != TEAMList){
            for (var i = 0; i < TEAMList.length; i++) {
                var TEAMCODE = TEAMList[i].TEAMCODE;
                if(teamCode_select == TEAMCODE){
                    $("#teamName").attr("readonly",true).css('background-color','#ccc').val(TEAMList[i].TEAMNAME);
                }
            }
        }else{
            $.message('error',"此机构下没有团队信息！");
            return;
        }
    }
    
    //查询中介-协议信息
    var agent_agreement_list;//存放销管返回的代理人代码和协议号的List,便于代理人代码改变时，协议号的同步改变
    function queryAgentAndAgreeInfo(){
        var prodSaleCode = $.trim($('#prodSaleCode').val());
        var dptCde = $.trim($('#deptNo').val());
        var channleCode_QD = $.trim($('#channleCode_QD').val());
        var newBsnsType =$.trim($('#newBsnsType').val());
        var teamCode = $.trim($('#teamCode').val());
        $.openLoading_jhk();
        $.ajax({
            url : "<%=path%>/outboundCard/queryAgentAndAgreeInfo?"+new Date().getTime(),
            type : 'POST',
            async : true,
            data:{
            	comCode:dptCde,
            	teamCode:teamCode,
            	businessSource:newBsnsType,
            	channelName:channleCode_QD,
            	prodCode:prodSaleCode
            },
            dataType:'json',
            success:function(result){
                $.closeLoading();
                if("error"==result.result) {
                	$.message('error',result.message);
                    return;
                }else if("fail"==result.result) {
                    $.message('error',"从销管处查询中介-协议信息失败，请联系管理员！");
                    return;
                } else if("success"==result.result){
                	var select = document.getElementById("agentNo_select");
                    select.options.length = 0;
                    select.add(new Option("-----请选择-----",""));
                    agent_agreement_list = result.data;
                    for (var i = 0; i < agent_agreement_list.length; i++) {
                        var option = new Option();
                        option.text = agent_agreement_list[i].AGENTCODE + "-" + agent_agreement_list[i].AGENTNAME;
                        option.title = agent_agreement_list[i].AGENTCODE + "-" + agent_agreement_list[i].AGENTNAME;
                        option.value = agent_agreement_list[i].AGENTCODE;
                        select.add(option);
                    }
                    agentInfoSelect();
                }
            }
        });
    }
    
    //代理人代码可选状态
    function agentInfoSelect(){
        $('#agentNo_select_div').css('display','inline').val("");
        $('#agentNo').hide().val('');
        $('#agentName').val('');
        
        $('#protocolNo').attr("readonly",true).css('background-color','#ccc').val("");
    }
    
    //查询服务代码信息
    var servicenos_list;//存放销管返回的服务代码和服务名称的List,便于服务代码改变时，服务名称的同步改变
    function queryServiceNo(){
        var deptNo=$.trim($('#deptNo').val());
        var channleCode_QD = $.trim($('#channleCode_QD').val());
        var newBsnsType = $.trim($('#newBsnsType').val());
        var empNo = $.trim($('#empNo').val());
        var agentNo = $.trim($('#agentNo').val());
        //必须先选择归属渠道、业务来源、业务员代码、代理人代码，再获取
        if(channleCode_QD.length==0){$.message('error',"请先选择归属渠道");return;}
        if(newBsnsType.length==0){$.message('error',"请先选择业务来源");return;}
        if(empNo.length==0){$.message('error',"请先选择业务员代码");return;}

        $.openLoading_jhk();
        $.ajax({
            url : "<%=path%>/outboundCard/queryServiceNo?"+new Date().getTime(),
            type : 'POST',
            async : true,
            data:{
            	deptNo:deptNo,
            	newBsnsType:newBsnsType,
                channleCode_QD:channleCode_QD,
                empNo:empNo,
                agentNo:agentNo
            },
            dataType:'json',
            success:function(result){
                $.closeLoading();
                if("success"!=result.result) {
                    $.message('error',"从销管处查询服务代码信息失败，请联系管理员！");
                    return;
                }else{
                    var select = document.getElementById("serviceCode_select");
                    select.options.length = 0;
                    select.add(new Option("-----请选择-----",""));
                    servicenos_list = result.data;
                    for (var i = 0; i < servicenos_list.length; i++) {
                        var option = new Option();
                        option.text = servicenos_list[i].SERVICENO + "-" + servicenos_list[i].SERVICENAME;
                        option.title = servicenos_list[i].SERVICENO + "-" + servicenos_list[i].SERVICENAME;
                        option.value = servicenos_list[i].SERVICENO;
                        select.add(option);
                    }

                    serviceInfoSelect();
                }
            }
        });
    }
    
    //服务代码可选状态
    function serviceInfoSelect(){
        $('#serviceCode_select_div').css('display','inline').val("");
        $('#serviceCode').hide().val('');
        
        $('#serviceName').attr("readonly",true).css('background-color','#ccc').val("");
    }
    
    //服务代码改变时，同步改变服务名称
    function changeServiceCode(){
        var serviceCode_select = $.trim($("#serviceCode_select").val());
        $("#serviceCode").val(serviceCode_select);
        
        if(serviceCode_select.length==0) {
            $("#serviceName").val("");
            return;
        }
        
        for (var i = 0; i < servicenos_list.length; i++) {
            var SERVICENO = servicenos_list[i].SERVICENO;
            if(serviceCode_select == SERVICENO){
                $("#serviceName").val(servicenos_list[i].SERVICENAME);
            }
        }
    }
    
    //代理人代码改变时，同步改变协议号
    function changeAgentNo(){
        var agentNo_select = $.trim($("#agentNo_select").val());
        $("#agentNo").val(agentNo_select);
        
        if(agentNo_select.length==0){
            $("#protocolNo").val("");
            $("#agentName").val("");
            serviceInfoWrite();
            return;
        }
        
        for (var i = 0; i < agent_agreement_list.length; i++) {
            var AGENTCODE = agent_agreement_list[i].AGENTCODE;
            if(agentNo_select == AGENTCODE){
                if (agent_agreement_list[i].AGREEMENTNO.length > 13) {
                    $.message('error', "代理人协议号长度不能超过13位！");
                    return;
                }
                $("#protocolNo").val(agent_agreement_list[i].AGREEMENTNO);
                $("#agentName").val(agent_agreement_list[i].AGENTNAME);
                break;
            }
        }
        queryServiceNo();
        
    }
    //校验手续费比例 
    function agentRateChange(){
    	var agentRateHidden = $('#agentRateHidden').text();
    	var agentRate = $('#agentRate').val();
    	if(agentRate.length==0){
    		$('#agentRate').val(agentRateHidden);
    		agentRate=agentRateHidden;
    	}
    	if(agentRateHidden < agentRate){
    		$('#agentRateErr').css("display","block");
    		$('#agentRateErr').html("不能大于方案配置的上限值" +agentRateHidden);
    	}else{
    		$('#agentRateErr').css("display","none");
    		var eCount=$("#eCount").val()
			var singlePrem=$("#singlePrem").val();
			var totalPrem=$("#totalPrem").val();
    		var singleAgentFee = (agentRate*(Number(singlePrem))).toFixed(2);
			var totalAgentFee = (agentRate*(Number(totalPrem))).toFixed(2);
    		$('#singleAgentFee').val(singleAgentFee);
    		$('#totalAgentFee').val(totalAgentFee);
    	}
    }
	//保存关联销售信息
	function saveRelatedInfo(){
		var curunt=$('#switchPage').val();
		var planNo = $.trim($("#planNo").val());
		var newBsnsType = $.trim($("#newBsnsType").val());
		var channelType = $.trim($("#channleType").val());
		var channelCode = $.trim($("#channleCode_QD").val());
		var bsnsType = $.trim($("#bsnsType").val());
		var empNo = $.trim($("#empNo").val());
		var empName = $.trim($("#empName").val());
		var teamCode = $.trim($("#teamCode").val());
		var teamName = $.trim($("#teamName").val());
		var agentNo = $.trim($("#agentNo").val());
		var agentName = $.trim($("#agentName").val());
		var serviceCode = $.trim($("#serviceCode").val());
		var serviceName = $.trim($("#serviceName").val());
		var protocolNo = $.trim($("#protocolNo").val());
		var singlePrem = $.trim($("#singlePrem").val());
		var totalPrem = $.trim($("#totalPrem").val());
		var singleAgentFee = $.trim($("#singleAgentFee").val());
		var totalAgentFee = $.trim($("#totalAgentFee").val());
		var cardNo= $("#cardNo").val();
		var count= $("#count").val();
		var name= $("#name").val();
		var cardDefineId= $("#cardDefineId").val();
		var pricelessType= $("#pricelessType").val();
		var agentRate=$("#agentRate").val();

		if(planNo.length == 0){
			$.message("error", "出单方案名称为空！");
			return;
		}
		if(channelCode.length==0){
            $.message("error", "请选择归属渠道");
            $('#channleCode_QD').focus();
            return;
        }
        if(channelType.length==0){
            $.message("error", "请选择渠道类型");
            $('#channleType').focus();
            return;
        }
        if(newBsnsType.length==0){
            $.message("error", "请选择新业务来源");
            $('#newBsnsType').focus();
            return;
        }
        if(bsnsType.length==0){
            $.message("error", "请选择原业务来源");
            $('#bsnsType').focus();
            return;
        }
        if(empNo.length==0){
            $.message("error", "请选择业务员代码");
            $('#empNo_select').focus();
            return;
        }
        if(teamCode.length==0){
            $.message("error", "请选择团队代码");
            $('#teamCode_select').focus();
            return;
        }
        //原业务来源为19002-代理或19003-经纪，则代理人代码和代理协议号必填
        if(bsnsType=="19002" || bsnsType=="19003"){
            if(agentNo.length==0){
                $.message("error", "请选择代理人代码");
                $('#agentNo').focus();
                return;
            }
            if(protocolNo.length==0){
                $.message("error", "请输入代理协议号");
                $('#protocolNo').focus();
                return;
            }
            if(agentName.length==0){
                $.message("error", "请输入代理人名称");
                $('#agentName').focus();
                return;
            }
            
        }
        
        if(serviceCode.length==0){
            $.message("error", "请选择或输入服务代码");
            $('#serviceCode').focus();
            return;
        }
        
        if("block"==$('#agentRateErr').css("display")){
        	$.message("error", "手续费率上限不能大于方案配置的上限");
            $('#agentRate').focus();
            return;
        }
        
		//if(saleName.length == 0){
		//	$.message("error", "请选择销售渠道信息");
		//	$('#userSaleName').focus();
		//	return;
		//}
		var deptNo=$("#deptNo").val();;
		//for (var i = 0; i < sales_men_list.length; i++) {
		//	if(saleName == sales_men_list[i].EMP_NO) {
		//		deptNo=sales_men_list[i].DPT_CDE;
		//	}
		//}
		if(pricelessType=='0'){
			var preFee='Y';
		}else{
			var preFee='N';
		}
		var param = {
				name:name,
				cardNo:cardNo,
				count:count,
				deptNo:deptNo,
				planNo:planNo,
				cardDefineName:name,
				cchaLevel:newBsnsType,
				cchannleType:channelType,
				cchannleCode:channelCode,
				operatorNo:empNo,
				operatorName:empName,
				teamCode:teamCode,
				teamName:teamName,
				agentNo:agentNo,
				agentMan:agentName,
				cserviceCode:serviceCode,
				cserviceName:serviceName,
				agentProtocolNo:protocolNo,
				modalPremAmt:singlePrem,
				totPremAMt:totalPrem,
				agentFee:singleAgentFee,
				totAgentFee:totalAgentFee,
				isPreFee:preFee,
				cardDefineId:cardDefineId,
				agentPremRate:agentRate,
				bsnsType:bsnsType
			}
		//console.log(param)
		$.openLoading_jhk();
		$.ajax({
			url : "<%=path%>/outboundCard/saveAgentRelaCardInfo",
			type : 'POST',
			async : true,
			data: param,
			dataType:'json',
			success : function(result) {
				$.closeLoading();
				if("success"==result.result&&""!=result.message){
					if(curunt==undefined){
						curunt=1;
					}
					var flag='success';
					window.location.href = "<%=path%>/outboundCard/successBack?flag="+flag+"&pricelessType="+pricelessType;
				}
				if("error"==result.result && ""!=result.message){
					$.message("error",result.message);
				}
				if("fail"==result.result){
		    		$.message("error", "系统错误,请联系管理员");
		    	}
			}
		});
	}
	function back(){
		window.location.href = "<%=path%>/outboundCard/outbound";
	}
	</script>	
	
</head>
<body>
    <input type="hidden" id="name" name="name" value="${name}"/>
    <input type="hidden" id="cardDefineId" name="cardDefineId" value="${cardDefineId}"/>
    <input type="hidden" id="count" name="count" value="${count}"/>
    <input type="hidden" id="cardNo" name="cardNo" value="${cardNo}"/>
    <input type="hidden" id="pricelessType" name="pricelessType" value="${pricelessType}"/>
    <input type="hidden" id="deptNo" name="deptNo" value="${deptNo}"/>
    <input type="hidden" id="planNo" name="planNo" value="${planNo}"/>
    <input type="hidden" id="prodCode" name="prodCode"/>
    <input type="hidden" id="prodSaleCode" name="prodSaleCode"/>
    <div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
		            <td>
		              <img src="./images/current_1.jpg">
		            </td>
		            <td class="current_table_1_td">
		              <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
		                <span style=" color:#136bab; ">激活卡管理
		                	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>激活卡出库
		                	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>关联销售信息
		            	</span>
		            </td>
		            <td><img src="./images/current_3.jpg"></td>
	        	</tr>
			</tbody>
		</table>
	</div>
	<!-- style="border: 1px solid #bbcddb; width: 100%; " -->
	<div id="main"  class="clearfix">
    <div id="agentInfoDiv" style="padding-right:10px;width:50%; box-sizing: border-box; float: left">
		<table class="table_05">
	       	<tbody>
	        	<tr>
	            	<td colspan="2" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">关联销售信息
	            	</td>
	            </tr>
	            <tr>
	              <th>出单机构：</th>
	              <td><input name="deptName" id="deptName" value="${deptName}" type="text" class="input_text" readonly='readonly' style=' background-color: #ccc;width:250px;'>
	              <span class="red" style="margin-left: -5px">*</span>
	              </td>
                </tr>
	            <tr>
                   <th width="10%">出单方案名称：</th>
                   <td width="40%">
		              	<!-- <select id="planInfo" onchange="planNameChange()" class="select_1" style="width:250px;"></select> -->
                  	    <input name="planName" id="planName" value="${planName}" type="text" class="input_text" readonly='readonly' style=' background-color: #ccc;width:250px;'>
                  	    <span class="red" style="margin-left: -5px">*</span>
                   </td>
	            </tr>
                <tr>
                   <th width="10%">业务员代码：</th>
                   <td width="40%">
                        <input type="hidden" id="empNo" name="empNo" maxlength="10"/>
                        <select id="empNo_select" onchange="changeEmpNo()" class="select_1 valid" style="visibility: visible;"></select>
                        <span class="red" style="margin-left: -5px">*</span>&nbsp;
                    </td>
                </tr>
                <tr>
                   <th width="10%">业务员名称：</th>
                   <td width="40%">
                        <input id="empName" class="input_text" style="width:250px">
                    </td>
                </tr>
                <tr>
                   <th width="10%">团队代码：</th>
                   <td width="40%">
                        <input type="hidden" id="teamCode" name="teamCode" maxlength="11"/>
                        <select id="teamCode_select" onchange="changeTeamCode()" class="select_1"></select>
                        <span class="red" style="margin-left: -5px">*</span>&nbsp;
                    </td>
                </tr>
                <tr>
                   <th width="10%">团队名称：</th>
                   <td width="40%">
                        <input id="teamName" class="input_text" style="width:250px">
                        <span class="red" style="margin-left: -5px">*</span>
                    </td>
                </tr>
                <tr>
                   <th width="10%">归属渠道：</th>
                   <td width="40%">
                        <select id="channleCode_QD" name="channleCode_QD" onchange="changeChannleCode_QD()" class="select_1">
                            <option value="">-----请选择业务员代码-----</option>
<%--                             <c:forEach var ="belongToChannel" items="${belongToChannelList}">
                            <option value="${belongToChannel.code}" title="${belongToChannel.codeName}">${belongToChannel.codeName}</option>
                            </c:forEach> --%>
                        </select>
                        <span class="red">*</span>
                  </td>
                </tr>
                <tr>  
                   <th width="10%">渠道类型：</th>
                   <td width="40%">
                      <select id="channleType"  class="select_1 valid" onchange="changeChannleType()" style="visibility: visible;">
                         <option value="">-----请选择归属渠道-----</option>
                         <%-- <c:forEach var ="channelType" items="${channelTypeList}">
                             <option value="${channelType.code}" title="${channelType.codeName}">${channelType.codeName}</option>
                         </c:forEach> --%>
                       </select><span class="red">*</span>
                  </td>
                </tr>
                <tr>
                   <th width="10%">新业务来源：</th>
                   <td width="40%">
                      <select id="newBsnsType"  onchange = "changeNewBsnsType()" class="select_1 valid" style="visibility: visible;" name="Ssss">
                        <option value="">-----请选择渠道类型-----</option>
                        <%-- <c:forEach var ="newBSList" items="${newBSList}">
                            <option value="${newBSList.code}">${newBSList.codeName}</option>
                        </c:forEach> --%>
                      </select><span class="red">*</span>
                  </td>
                </tr>
                <tr>
                   <th width="10%">原业务来源：</th>
                   <td width="40%">
                      <select id="bsnsType" onchange = "bsnsTypeChange()" class="select_1 valid" style="visibility: visible;">
                         <option value="">-----请选择-----</option>
                                 <c:forEach var ="oldBSList" items="${oldBSList}">
                                     <option value="${oldBSList.code}">${oldBSList.codeName}</option>
                                 </c:forEach>
                      </select><span class="red">*</span>
                    </td>
                </tr>
                <tr>
                   <th width="10%">代理人代码：</th>
                   <td width="40%">
                        <div id="agentNo_select_div" style="display: none">
                                <select id="agentNo_select" onchange="changeAgentNo()" class="select_1"></select>
                         </div>
                        <input id="agentNo" name="agentNo" type="text" maxlength="20" class="input_text" style="width:250px"/>
                        <span class="red" style="margin-left: -5px">*</span>
                    </td>
                </tr>
                <tr>
                   <th width="10%">代理人名称：</th>
                   <td width="40%">
                        <input class="input_text" style="width:250px" id="agentName" name="agentName"/>
                        <span class="red" style="margin-left: -5px">*</span>
                    </td>
                </tr>
                <tr>
                   <th width="10%">代理人协议号：</th>
                   <td width="40%">
                        <input id="protocolNo" class="input_text" style="width:250px" maxlength="13"/>
                        <span class="red" style="margin-left: -5px">*</span>
                    </td>
                </tr>
                <tr>
                   <th width="10%">服务代码：</th>
                   <td width="40%">
                        <div id="serviceCode_select_div" style="display: none">
                            <select id="serviceCode_select" onchange="changeServiceCode()" class="select_1"></select>
                        </div>
                        <input id="serviceCode" class="input_text" style="width:250px"/>
                        <span class="red" style="margin-left: -5px">*</span>&nbsp;
                    </td>
                </tr>
                <tr>
                   <th width="10%">服务名称：</th>
                   <td width="40%">
                        <input id="serviceName" class="input_text" style="width:250px"/>
                </tr>
	        </tbody>
	    </table>	    
		<div align="center">
		   <input class="input_button_3" name="" type="button" onclick="saveRelatedInfo()" value="确定">&nbsp;&nbsp;
           <input class="input_button_3" name="" type="button" onclick="back()" value="取消">
		</div>
    </div>
    <div id="countMoneyDiv" style="padding-left:10px;width:50%; box-sizing: border-box;  float: left">
    	<table class="table_05">
	       	<tbody>
	        	<tr>
	            	<td  colspan="2" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">费用信息
	            	</td>
	            </tr>
	            <tr>
	              <th width="10%">卡数：</th>
	              <td width="40%"><input name="eCount" id="eCount" value="${count}" type="text" class="input_text" readonly='readonly' style=' background-color: #ccc;width:250px;'>
	              </td>
              </tr>
              <tr>
                <th width="10%">单张保费：</th>
                <td width="40%"><input name="singlePrem" id="singlePrem" value="${premAmt}" type="text" class="input_text" readonly='readonly' style=' background-color: #ccc;width:250px;'>
                </td>
              </tr>
              <tr>
              	<th width="10%">总保费：</th>
                <td width="40%"><input name="totalPrem" id="totalPrem" value="${totalPrem}" type="text" class="input_text" readonly='readonly' style=' background-color: #ccc;width:250px;'>
                </td>
              </tr>
              <tr>
                <th width="10%">手续费率：</th>
                <td width="40%"><input name="agentRate" id="agentRate" value="" type="text" class="input_text" style='width:250px;float: left' onchange="agentRateChange()">
                <span id="agentRateHidden" style='display:none'></span><span id='agentRateErr' style='color: red;display:none'>不能大于方案配置的上限值：</span>
                </td>
              </tr>
              <tr>
                <th width="10%">单张手续费：</th>
                <td width="40%"><input name="singleAgentFee" id="singleAgentFee" value="" type="text" class="input_text" readonly='readonly' style=' background-color: #ccc;width:250px;'>
                </td>
              </tr>
              <tr>
              	<th width="10%">总手续费：</th>
                <td width="40%"><input name="totalAgentFee" id="totalAgentFee" value="" type="text" class="input_text" readonly='readonly' style=' background-color: #ccc;width:250px;'>
                </td>
              </tr>
	        </tbody>
	    </table>
    </div>
    </div>
    <table class="table_02" id="table">
		<tr>
			<td>
	  			<div id="cardDiv" style="width:98%;margin:5px" >
					<table id="cardInfoTable" class="content_table_1">
						<thead>
						    <tr>
		            	        <td  colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">出库卡单信息
		            	        </td>
		                    </tr>
							<tr class="f1">
								<th style="width:10%;">卡定义名称</th>
								<th style="width:5%;">卡号</th>
								<th style="width:3%;">保费</th>
								<th style="width:5%;">失效日期</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txCardpageDIV" class="page"></div>
				</div>
			</td>
		</tr>
	</table>
	
	<div id="Loading" style="display:none" align="center">
		<img src="./images/loading.gif" />
	</div>
</body>
</html>